package com.yunhe.authority.service.company;

import com.yunhe.authority.domain.authority.User;
import com.yunhe.authority.domain.company.Employee;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.common.exception.UniqueConstraintsException;
import com.yunhe.common.model.PageParam;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface EmployeeService {

    /**
     * 新增用户
     * @param employee 员工对象
     * @param companyId 企业id
     * @param roleIds 角色组织id
     * @return
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    Employee createEmployee(Employee employee, Long companyId, String roleIds) throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException;

    /**
     * 根据ids删除用户
     * @param employeeIds
     * @throws ArgumentErrorException
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    void deleteEmployee(String employeeIds) throws ArgumentErrorException;

    List<Employee> resetPassword(String ids) throws ArgumentErrorException;

    /**
     * 禁用/恢复员工账号
     * @param ids
     * @param activity
     * @param headerUser
     * @throws ArgumentErrorException
     */
    void disableRecoveryEmployee(String ids, String activity, User headerUser) throws ArgumentErrorException;

    /**
     * 根据ID获得员工对象
     * @param employeeId 员工ID
     */
    Employee findByEmployeeId(Long employeeId);

    /**
     * 修改员工对象
     * @param employee
     * @param companyId
     * @param roleIdList
     * @return
     * @throws ObjectNotFoundException
     * @throws ArgumentErrorException
     * @throws UniqueConstraintsException
     */
    void updateEmployee(Employee employee, Long companyId, List<Long> roleIdList) throws ObjectNotFoundException, ArgumentErrorException, UniqueConstraintsException;

    Iterable<Employee> getEmployeeByCondition(Long companyId, String roleType, PageParam pageParam) throws ArgumentErrorException;

    Page<Employee> getEmployeesByCompanyIdAndRoleId(Long companyId, Long roleId, String keywords, PageParam pageParam);

    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    void employeeUnbindCompanyRole(Long employeeId, Long roleId);

    List<Employee> getEmployeesByPhoneAndPassword(String phone, String password);

    /**
     * 根据手机号获得员工对象
     * @param phone 员工手机号
     */
    Employee findByPhone(String phone);

    /**
     * 根据手机号获得员工对象列表
     * @param phone 员工手机号
     */
    List<Employee> findListByPhone(String phone);

    /**
     * 根据手机号统一修改密码
     * @param phone
     * @param password
     * @return
     */
    void updateEmployeePasswordByPhone(String phone, String password);
}
